#!/bin/bash -e

function info() {
echo Usage: `basename $0` [-s sep] 'dir_to_a_cancer cancer_name'
exit 2
}

while getopts  ":p:f:s:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
		s) sep=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 2 ]; then info; fi
if test -z "$sep"; then sep=,; fi

. $var

cd $1
j=0
for i in $(ls *); do j=$((j+1)); awk '{if($2=="NA"){printf("NA'"$sep"'") }else{printf("%4.3f'"$sep"'", $2)}}END{printf("'"$2"'\n")}' $i > $out_prefix.$j.beta; done && cat $out_prefix.*.beta > $out_prefix.beta

# sed -i s/$/zcx/ 1.list